package com.wfx.controller;


import com.wfx.entity.*;
import com.wfx.service.ISysRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@CrossOrigin
@Api(description = "角色管理")
public class SysRoleController {

    @Autowired
    private ISysRoleService iSysRoleService;

    @PostMapping("/search")
    @ApiOperation("角色查询")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public PageResult<SysRole> search(@RequestBody @ApiParam("角色分页加条件") PageDTO<SysRole> pageDTO){
        return iSysRoleService.search(pageDTO);
    }

    @PostMapping("save")
    @ApiOperation("角色添加与修改")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public Result save(@RequestBody @ApiParam("角色实体") SysRole sysRole){
        return iSysRoleService.addOrUpdate(sysRole);
    }

    @PostMapping("delByIds")
    @ApiOperation("角色批量删除")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public Result delByIds(@RequestBody @ApiParam("角色id集合") List<String> roleCodes){
        return iSysRoleService.delBrands(roleCodes);
    }

    @PostMapping("delOne")
    @ApiOperation("角色删除")
    @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
    public Result delOne(@RequestBody @ApiParam("角色实体") SysRole sysRole){
        return iSysRoleService.delOne(sysRole);
    }



}
